package com.tjetc.controller;

import com.tjetc.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.tjetc.constant.CodeConstant.TIMEOUT;
import static com.tjetc.constant.RedisConstant.*;

/**
 * @author zc
 * @Date 2025/7/17 下午2:09
 */
@RestController
@RequestMapping("operation")
public class OperationController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @RequestMapping("findState")
    public Result findState(@RequestParam("operationId") String operationId){
        HashOperations<String, Object, Object> ops = stringRedisTemplate.opsForHash();
        Object getState = ops.get(OPERATION_KEY + operationId, STATE);
        if (getState == null){
            return new Result().setCode(TIMEOUT);
        }
        Integer state = Integer.parseInt((String)getState );
        String desc = (String) ops.get(OPERATION_KEY + operationId, DESC);
        return new Result().setCode(state).setMsg(desc);
    }
}
